package com.cn.kafka.web;

import com.cn.kafka.producer.Sender;
import com.cn.kafka.producer.ManualProducer;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created by Administrator on 2018/1/3.
 */
@RestController
@Slf4j
public class TestSendWeb {
    private static final Logger logger = LoggerFactory.getLogger(TestSendWeb.class);
    @Autowired
    private  Sender sender;

    @Autowired
    private ManualProducer manualProducer;

    @GetMapping("manualProducer")
    public void manualProducer() {
        String info = "我就是我，是手动提交偏移量"+UUID.randomUUID().toString();
        log.info(info);
        manualProducer.send(info);
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 发送
     * @return
     * @throws InterruptedException
     */
    @GetMapping("send")
    public String send() throws InterruptedException {
        int i=0;
        while(i<100){
            sender.sendMessage();
//            sender.sendMessage2();
            Thread.sleep(1);
            i++;
        }
        return "";
    }
}
